using System.Collections.Generic;
using UnityEngine;

public class LightworldInventory : MonoBehaviour
{
	public List<InventoryItem> PlayerInventory = new List<InventoryItem>();

	private static LightworldInventory instance;

	public static LightworldInventory Instance => instance;

	private void Awake()
	{
		if ((Object)(object)instance != (Object)null && (Object)(object)instance != (Object)(object)this)
		{
			Object.Destroy((Object)(object)((Component)this).gameObject);
			return;
		}
		instance = this;
		Object.DontDestroyOnLoad((Object)(object)instance);
	}

	public void ClearInventory()
	{
		PlayerInventory.Clear();
	}

	public void SetupNewInventory(InventoryItem[] items)
	{
		if (items.Length == 0)
		{
			return;
		}
		foreach (InventoryItem inventoryItem in items)
		{
			if ((Object)(object)inventoryItem != (Object)null)
			{
				PlayerInventory.Add(inventoryItem);
			}
		}
	}

	public void RemoveItem(int itemIndex)
	{
		if (PlayerInventory.Count > 0 && (Object)(object)PlayerInventory[itemIndex] != (Object)null)
		{
			PlayerInventory[itemIndex] = null;
			SortInventory();
		}
	}

	public void SortInventory()
	{
		PlayerInventory.Sort((InventoryItem a, InventoryItem b) => (((Object)(object)a == (Object)null) ? 1 : 0) - (((Object)(object)b == (Object)null) ? 1 : 0));
	}
}
